package cn.mr;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import java.io.IOException;
public class NewsMapper extends Mapper<LongWritable, Text, Text, NewsBean> {
    NewsBean newsBean = new NewsBean();
    public void map(LongWritable key, Text value, Context context)
            throws IOException, InterruptedException {
        //每一行文本按“,”分割
        String[] fields = value.toString().split(",");
        if (fields.length <= 4) {
            // 提取类别
            String category = fields[3];
            // 提取标题和热度指数
            String title = fields[0];
            long heat = Long.parseLong(fields[2]);;
            newsBean.setTitle(title);
            newsBean.setHeat(heat);
            newsBean.setCategory(category);
            context.write(new Text(category), newsBean);
        }
    }
}
